home *** CD-ROM | disk | FTP | other *** search
- library chat;
-
- uses
- Windows, SysUtils,
- Classes,
- Httpext,
- ISAPISock;
-
- var
- // Note: All threads use this string to share info. This is
- // dangerous and should be mediated. It is done this way here
- // for illustration only.
- JustSubmitted: ShortString;
-
- procedure SendChatText(sock: TISAPISock);
- var
- lastString: String;
- skip: Integer;
- begin
- lastString:='';
-
- with sock do
- begin
- HHeader('ISAPI Chat', hcLtGray, hcBlack, hcBlue);
- HPageStart;
-
- JustSubmitted:=GetServerVariable('REMOTE_ADDR')+' just joined!';
-
- try
- repeat
- if lastString<>JustSubmitted then
- begin
- HLine( HBold(GetServerVariable('REMOTE_ADDR')+': ')+JustSubmitted);
- lastString:=JustSubmitted;
- end;
- Sleep(100);
-
- // Once a second we'll squirt out a space. HTML doesn't care
- // and will in fact eat these up. The write will, however,
- // generate an exception iff the pipe is ever broken.
- Inc(skip);
- if (skip mod 10)=0 then
- Write(' ');
-
- until FALSE;
- finally
- JustSubmitted:=GetServerVariable('REMOTE_ADDR')+' just left!';
- end;
-
- HPageEnd;
- end;
- end;
-
- procedure SendChatForm(sock: TISAPISock);
- begin
- with sock do
- begin
- //Writeln('HTTP/1.0 200 OK');
- //Writeln('Content-type: text/html');
- //Writeln('Expires: 0');
- //Writeln('');
-
- HHeader('ISAPI Chat', hcLtGray, hcBlack, hcBlue);
- HPageStart;
-
- HFormStart('POST', '/bin/chat.dll');
- HEditBox('', 'ChatString', '', 50, 50);
- HFormEnd('Send', '');
-
- HPageEnd;
- end;
- end;
-
- //
- // Called anytime a GET is performed on this DLL
- //
- procedure ProcessGet(sock: TISAPISock);
- var
- query: String;
- begin
- with sock do
- begin
- // Blast out a header
- Writeln('HTTP/1.0 200 OK');
- Writeln('Content-type: text/html');
- Writeln('Expires: 0');
- Writeln('');
-
- //HHeader('ISAPI Chat', hcLtGray, hcBlack, hcBlue);
- //HPageStart;
-
- query:=GetServerVariable('QUERY_STRING');
-
- if query='ChatText' then
- begin
- SendChatText(sock)
- end
- else if query='ChatForm' then
- begin
- SendChatForm(sock)
- end
- else if query='' then
- begin
- Writeln('<HTML><HEAD>');
- Writeln('<TITLE>Test</TITLE>');
- Writeln('</HEAD>');
-
- Writeln('<FRAMESET ROWS="90%,10%">');
- Writeln('<FRAME SCROLL=AUTO SRC="/bin/chat.dll?ChatText">');
- Writeln('<FRAME SCROLL=NO SRC="/bin/chat.dll?ChatForm">');
- Writeln('</FRAMESET>');
- Writeln('</HTML>');
- end;
- end;
- end;
-
-
- procedure ProcessPost(sock: TISAPISock);
- begin
- with sock do
- begin
- JustSubmitted:=EscapeDecode(GetFormVal('ChatString'));
- SendChatForm(sock);
- end;
- end;
-
- // CASE MATTERS FOR THIS FUNCTION NAME
- function GetExtensionVersion(var ver: THSE_VERSION_INFO): Boolean; stdcall;
- begin
- result:=True;
- end;
-
- // CASE MATTERS FOR THIS FUNCTION NAME
- function HttpExtensionProc(var ecb: TEXTENSION_CONTROL_BLOCK): LongInt; stdcall;
- var
- sock: TISAPISock;
- method: String;
- begin
- try
- // Create the socket helper
- sock:=TISAPISock.Create(ecb);
-
- method:=sock.GetServerVariable('REQUEST_METHOD');
- if method='GET' then
- ProcessGet(sock)
- else if method='POST' then
- ProcessPost(sock)
- else
- begin
- sock.Writeln('HTTP/1.0 200 OK');
- sock.Writeln('Content-type: text/html');
- sock.Writeln('');
- sock.Writeln('I didn''t understand that request');
- end;
-
-
- // Return a normal status code
- StrLCopy( ecb.lpszLogData, PChar('DLL Finished with no errors'), HSE_LOG_BUFFER_LEN-1);
- Result:=HSE_STATUS_SUCCESS;
-
- // Free the socket
- sock.Free;
- except
- ;
- end;
- end;
-
- // * REQUIRED FOR DYNAMIC BINDING.
- // * Index values aren't need.
- // * Case doesn't matter here.
- exports
- GetExtensionVersion,
- HttpExtensionProc;
-
- begin
- end.
-
-